﻿Imports System.Security.Cryptography
Imports System.Text
Imports System.Security
Imports System.Net.Sockets
Imports System.Net.Mail

Imports Security.Security
Imports Security.PhysicalDrive

Public Class frmreg

    Private Sub frmreg_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        If IsTopMost = True Then
            frmmain.TopMost = IsTopMost
        End If
        Me.Close()
    End Sub

    Private Sub frmreg_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Dispose()
    End Sub

    Private Sub frmreg_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim HardDiskNumber As String
        Dim Security As New Security.Security
        Dim PhysicalDrive As New Security.PhysicalDrive

        Me.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Bottom - Me.Height) / 2)
        HardDiskNumber = PhysicalDrive.GetHDDID(0)
        TextBox1.Text = UCase(Security.MD5(HardDiskNumber, 32))
        'TextBox2.Text = GetKey(TextBox1.Text)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim KeyFile As String
        Dim KeyText As String
        Dim Security As New Security.Security

        KeyFile = My.Application.Info.DirectoryPath & "\SwTool.key"
        KeyText = Trim(TextBox2.Text)
        My.Computer.FileSystem.WriteAllText(KeyFile, KeyText, False)

        If KeyText = Security.GetKey(TextBox1.Text) Then
            IsReg = True
            frmmain.Menu_Reg.Enabled = False
            frmmain.Text = AppTitle
            MsgBox("注册成功")
            Me.Dispose()
        Else
            TextBox2.Text = ""
            MsgBox("注册失败")
        End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Dim client = New SmtpClient()
        'Dim UserName As String

        'System.Diagnostics.Process.Start(taobao)
        'UserName = InputBox("您的email，请在付款时留下以便确认", "注册")

        'If Trim(UserName) = "" Then Exit Sub
        'Application.DoEvents()

        'client.Host = "smtp.163.com"
        'client.UseDefaultCredentials = False
        'client.Credentials = New System.Net.NetworkCredential("likai14983@163.com", "yyz840101")    '星号改成自己邮箱的密码
        'client.DeliveryMethod = SmtpDeliveryMethod.Network
        'client.Timeout = 10000

        'Dim message = New MailMessage("likai14983@163.com", "likai14983@163.com")
        'message.Subject = "SwTool注册"
        'message.Body = UserName & "-" & TextBox1.Text
        'message.BodyEncoding = System.Text.Encoding.UTF8
        'message.IsBodyHtml = True

        'Try
        '    client.Send(message)
        '    MsgBox("你的序列号已经通过电子邮件发送给leaky，作者将回复注册码文件给您，谢谢你的支持！")
        'Catch ex As Exception
        '    MessageBox.Show(("Send Email Failed." + ex.ToString()))
        'End Try
        'message.Dispose()


        Try
            System.Diagnostics.Process.Start(Taobao_SW2007)
        Catch ex As Exception
            ' The error message
            'MessageBox.Show("Unable to open link that was clicked.")
        End Try
    End Sub
End Class